package com.jtech.together.view.weight.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 好友操作dialog
 * Created by wuxubaiyang on 2017/5/12.
 */

public class FriendOptionDialog {
    private AlertDialog.Builder builder;
    private SimpleAdapter simpleAdapter;
    private String[] options = {"用户信息", "删除好友"};

    public FriendOptionDialog(Context context) {
        this.builder = new AlertDialog.Builder(context);
        //实例化适配器
        this.simpleAdapter = new SimpleAdapter(context,
                getOption(), android.R.layout.simple_list_item_1,
                new String[]{"option"}, new int[]{android.R.id.text1});
    }

    public static FriendOptionDialog build(Context context) {
        return new FriendOptionDialog(context);
    }

    /**
     * 设置点击事件
     *
     * @param onClickListener
     * @return
     */
    public FriendOptionDialog setOnClickListener(DialogInterface.OnClickListener onClickListener) {
        builder.setAdapter(simpleAdapter, onClickListener);
        return this;
    }

    /**
     * 显示dialog
     */
    public void show() {
        builder.show();
    }

    /**
     * 获取设置集合
     *
     * @return
     */
    private List<Map<String, String>> getOption() {
        List<Map<String, String>> datas = new ArrayList<>();
        for (int i = 0; i < options.length; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("option", options[i]);
            datas.add(map);
        }
        return datas;
    }
}